//
//  HTCityIntroViewController.m
//  HeartTravel
//
//  Created by lanou on 15/11/2.
//  Copyright © 2015年 陈文杰. All rights reserved.
//

#import "HTCityIntroViewController.h"
#import "HTWebViewController.h"
#import "HTCityViewController.h"
#import "UIImageView+WebCache.h"
#import "HTImageViewController.h"
@interface HTCityIntroViewController ()
@property (nonatomic, strong) UIImageView *posterImageView;
@property (nonatomic, strong) NSTimer *timer;
@end

@implementation HTCityIntroViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.topView.backgroundColor = [UIColor colorWithRed:0.351 green:0.359 blue:0.350 alpha:1.000];
    [self.leftButton setBackgroundImage:[UIImage imageNamed:@"返回"] forState:(UIControlStateNormal)];
    [self.leftButton addTarget:self action:@selector(didClickBackRootViewController) forControlEvents:(UIControlEventTouchUpInside)];
    self.titleLabel.text = self.titleName;
    [self addButton];
    // 计时器 用来展示播放时间
    _timer = [NSTimer timerWithTimeInterval:3.0 target:self selector:@selector(imageViewTochangeFrame) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSDefaultRunLoopMode];
}

- (void)imageViewTochangeFrame{
    [UIView animateWithDuration:3.0 animations:^{
        _posterImageView.frame = CGRectMake(-60, 70, SCREEN_WIDTH + 120, 280);
    } completion:^(BOOL finished) {
        _posterImageView.frame = CGRectMake(0, 70, SCREEN_WIDTH, 250);
    }];
}

- (void)addButton{
     _posterImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 70, SCREEN_WIDTH, SCREEN_HEIGHT - 400)];
    [_posterImageView sd_setImageWithURL:[NSURL URLWithString:self.posterUrl]];
    [self.view addSubview:_posterImageView];
    
    CGFloat width = (SCREEN_WIDTH - 160)/2;
    UIButton *button1 = [UIButton buttonWithType:(UIButtonTypeCustom)];
    button1.frame = CGRectMake(65, SCREEN_HEIGHT - 300, width, width);
    [button1 addTarget:self action:@selector(didClickToTravelScenic) forControlEvents:(UIControlEventTouchUpInside)];
    [button1 setBackgroundImage:[UIImage imageNamed:@"Travel_Transportation_128px_1184555_easyicon.net"] forState:(UIControlStateNormal)];
    [self.view addSubview:button1];
    UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(0, width - 30, width, 30)];
    label1.font = [UIFont systemFontOfSize:18];
    label1.textColor = [UIColor whiteColor];
    label1.backgroundColor = [UIColor colorWithWhite:0.605 alpha:1.000];
    label1.alpha = 0.5;
    label1.layer.cornerRadius = 5;
    label1.layer.masksToBounds = YES;
    label1.text = @"旅行景点";
    label1.textAlignment = NSTextAlignmentCenter;
    [button1 addSubview:label1];
    
    UIButton *button2 = [UIButton buttonWithType:(UIButtonTypeCustom)];
    button2.frame = CGRectMake(95 + width, SCREEN_HEIGHT - 300, width, width);
    [button2 addTarget:self action:@selector(didClickToTravelMustGo) forControlEvents:(UIControlEventTouchUpInside)];
    [button2 setBackgroundImage:[UIImage imageNamed:@"Travel_Transportation_128px_1184556_easyicon.net"] forState:(UIControlStateNormal)];
    [self.view addSubview:button2];
    UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(0, width - 30, width, 30)];
    label2.font = [UIFont systemFontOfSize:18];
    label2.textColor = [UIColor whiteColor];
    label2.backgroundColor = [UIColor colorWithWhite:0.605 alpha:1.000];
    label2.alpha = 0.5;
    label2.layer.cornerRadius = 5;
    label2.layer.masksToBounds = YES;
    label2.text = @"非去不可";
    label2.textAlignment = NSTextAlignmentCenter;
    [button2 addSubview:label2];
    
    UIButton *button3 = [UIButton buttonWithType:(UIButtonTypeCustom)];
    button3.frame = CGRectMake(65, SCREEN_HEIGHT - 290 + width, width, width);
    [button3 addTarget:self action:@selector(didClickToTravelTop) forControlEvents:(UIControlEventTouchUpInside)];
    [button3 setBackgroundImage:[UIImage imageNamed:@"king_crown_128px_537019_easyicon.net"] forState:(UIControlStateNormal)];
    [self.view addSubview:button3];
    UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(0, width - 30, width, 30)];
    label3.font = [UIFont systemFontOfSize:18];
    label3.textColor = [UIColor whiteColor];
    label3.backgroundColor = [UIColor colorWithWhite:0.605 alpha:1.000];
    label3.alpha = 0.5;
    label3.layer.cornerRadius = 5;
    label3.layer.masksToBounds = YES;
    label3.text = @"当地特色";
    label3.textAlignment = NSTextAlignmentCenter;
    [button3 addSubview:label3];
    
    UIButton *button4 = [UIButton buttonWithType:(UIButtonTypeCustom)];
    button4.frame = CGRectMake(95 + width, SCREEN_HEIGHT - 290 + width, width, width);
    [button4 addTarget:self action:@selector(didClickToTravelAttention) forControlEvents:(UIControlEventTouchUpInside)];
    [button4 setBackgroundImage:[UIImage imageNamed:@"text_notebook_128px_1092527_easyicon.net"] forState:(UIControlStateNormal)];
    [self.view addSubview:button4];
    UILabel *label4 = [[UILabel alloc]initWithFrame:CGRectMake(0, width - 30, width, 30)];
    label4.font = [UIFont systemFontOfSize:18];
    label4.textColor = [UIColor whiteColor];
    label4.backgroundColor = [UIColor colorWithWhite:0.605 alpha:1.000];
    label4.alpha = 0.5;
    label4.layer.cornerRadius = 5;
    label4.layer.masksToBounds = YES;
    label4.text = @"实用须知";
    label4.textAlignment = NSTextAlignmentCenter;
    [button4 addSubview:label4];
}
// 旅行景点
- (void)didClickToTravelScenic{
    HTCityViewController *cityVC = [[HTCityViewController alloc]init];
    cityVC.titleName = self.titleName;
    cityVC.urlString = self.urlString;
    [self.navigationController pushViewController:cityVC animated:nil];
}
// 不可错过
- (void)didClickToTravelMustGo{
    NSString *mustGoStr = [@"http://web.breadtrip.com/mobile/destination" stringByAppendingFormat:@"%@%@", self.urlString, @"intro/"];
    HTWebViewController *webVC = [[HTWebViewController alloc]init];
    webVC.urlString = mustGoStr;
    [self.navigationController pushViewController:webVC animated:nil];
}
// Top 10
- (void)didClickToTravelTop{
    NSString *travelTopStr = [@"http://web.breadtrip.com/mobile/destination" stringByAppendingFormat:@"%@%@", self.urlString, @"top10_list/"];
    HTWebViewController *webVC = [[HTWebViewController alloc]init];
    webVC.urlString = travelTopStr;
    [self.navigationController pushViewController:webVC animated:nil];
}
// 实用须知
- (void)didClickToTravelAttention{
    NSString *attentionStr = [@"http://web.breadtrip.com/mobile/destination" stringByAppendingFormat:@"%@%@", self.urlString, @"overview/"];
    HTWebViewController *webVC = [[HTWebViewController alloc]init];
    webVC.urlString = attentionStr;
    [self.navigationController pushViewController:webVC animated:nil];
}

- (void)didClickBackRootViewController{
    [self.navigationController popToRootViewControllerAnimated:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
